/*
 * util.h
 *
 *  Created on: Oct 25, 2013
 *      Author: jiang
 */

#ifndef UTIL_H_
#define UTIL_H_

#include <stdio.h>
#include <stdint.h>
#include "kseq.h"
#include "global.h"
#include "bntseq.h"


KSEQ_INIT(gzFile, gzread)

#ifdef __cplusplus
extern "C" {
#endif


#define TAKE_N_BITS_FROM_RIGHT(b, p, n) ((b) >> (p)) & ((1 << (n)) - 1)  //p:start index (right most is 0), n number of bits.


typedef struct{
	int parameter;
	uint32_t chunck_size;
	int firstZ;// for each read, we get first Z number of distinct kmer
	int allowMismatch; //If > it, then we do alignment.

	int score_threshold;
	int extend_len;  // when do local aligment, length of ref = readlength + extend_len
	int top_Z;  //consider top_Z high frequency positions
	float good_enough_percent_support;//

	float ert; // error rate of reads
	float indelrt;// percent of errors are indel
	float distinctPercent; //percentage of distinct kmer at reference

	int kmerLen;


	int a; //Score of a match [1]
	int b; //Mismatch penalty [3]
	int q; //Gap open penalty [5]
	int r; //Gap extension penalty. The penalty for a contiguous gap of size k is q+k*r. [2]
	int bw; //-w INT	 Band width in the banded alignment [33]
}opt_t;	//type for option

typedef struct{
	int64_t l_pac;
	int32_t n_seqs; //number of reference sequence
	FILE *fp_pac; //name of file containing compact presentation of reference file

}refseqs_t; //store reference sequence

typedef struct{
	int lookupMethod;
}option;  //store reference index
int compareParSecondDec(const pair *s1, const pair *s2);
uint32_t hammingDistance(uint8_t *a, uint8_t *b,  uint32_t len);
uint8_t *getTarget(const uint8_t *pac, int64_t l_ref_oneStrand, uint64_t position, uint32_t targetLen);
uint8_t *add1(const kseq_t *seq, bntseq_t *bns, uint8_t *pac, int64_t *m_pac, int *m_seqs, int *m_holes, bntamb1_t **q);
#ifdef __cplusplus
}
#endif


#endif /* UTIL_H_ */
